package com.dc.project.controller.user;

import com.dc.project.constant.ControllerConstant;
import com.own.aop.login.LoginIgnore;
import com.own.aop.operation.LogOperationAop;
import com.own.aop.operation.LogOperationModuleAop;
import com.own.business.resource.business.service.ResourceService;
import com.own.business.resource.entity.vo.FileRecordVo;
import com.own.component.common.base.controller.BaseController;
import com.own.component.common.model.R;
import com.own.component.common.model.ResultModel;
import com.own.constant.ConstantApiPrefix;
import com.own.constant.ConstantBeanSuffix;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * UserClientResourceController
 *
 * @author chenxueli
 * @date 2025-03-19 16:24:03
 */
@Slf4j
@Tag(name = "用户资源文件API接口" + ConstantBeanSuffix.CONTROLLER)
@RestController
@LoginIgnore
@CrossOrigin("*")
@LogOperationModuleAop("用户资源文件API接口")
@RequestMapping(ConstantApiPrefix.BASE_API_V1_PREFIX + ControllerConstant.PREFIX_USER_API + "resource")
public class UserClientResourceController extends BaseController {

    @Resource
    private ResourceService resourceService;

    @LogOperationAop
    @Operation(summary = "上传文件")
    @PostMapping({"/upload"})
    public ResultModel<FileRecordVo> upload(@Parameter(description = "上传方式 默认default") @RequestParam(defaultValue = "default", required = false) String method, @Parameter(description = "上传的文件", required = true) @RequestPart MultipartFile file) {
        FileRecordVo vo = this.resourceService.upload(method, file);
        return R.success(vo);
    }

}
